﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class CountryBus
    {
        private CountryDao dao;
        public CountryBus()
        {
            dao = new CountryDao();
        }

        public bool insert(Country country) {
            return dao.insert(country);
        }

        public bool update(Country country) {
            return dao.update(country);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public Country get(int id) {
            DataTable dt = dao.get(id);
            Country country = new Country();

            if (dt.Rows.Count > 0)
            {
                country.Id = Convert.ToInt32(dt.Rows[0]["CNT_ID"]);
                country.Name = dt.Rows[0]["CNT_NAME"].ToString();
                country.Desc = dt.Rows[0]["CNT_DESC"].ToString();
            }
            return country;
        }

        public List<Country> getAll() {
            DataTable dt = dao.getAll();
            List<Country> list = new List<Country>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    Country country = new Country();
                    country.Id = Convert.ToInt32(dr["CNT_ID"]);
                    country.Name = dr["CNT_NAME"].ToString();
                    country.Desc = dr["CNT_DESC"].ToString();

                    list.Add(country);
                }

            }
            return list;
        }
    }
}
